package com.dcivision.dms.taglib;

import java.io.IOException;

import javax.servlet.jsp.JspException;

import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.MessageResourcesFactory;
import com.dcivision.framework.SessionContainer;
import com.dcivision.framework.taglib.html.PermissionButtonTag;

/**
 * Button tag for dms new document
 *
 * @author henry.chan
 * @see PermissionButtonTag
 *
 */
public class DmsNewDocButtonTag extends PermissionButtonTag {

  private static final String BUTTON_CSS_STYLE = "but-newdoc";

  public DmsNewDocButtonTag() {
    super();
  }

  protected String getButtonEnabledMainClass() {
    return BUTTON_CSS_STYLE;
  }

  /**
   * Generate and return the html content
   *
   * @return Html content string
   * @throws IOException
   * @throws JspException
   */
  protected String getContent() throws JspException {
    StringBuffer content = new StringBuffer();
    SessionContainer sessionContainer = (SessionContainer) pageContext.getSession().getAttribute(GlobalConstant.SESSION_CONTAINER_KEY);
    boolean hasOnClick = hasOnClick();
    boolean hasLink = hasLink();

    // start rendering
    content.append("<span class='" + getButtonEnabledMainClass() + "'>");
    content.append("<div class='but_left'></div>");

    if (hasOnClick) {
      content.append("<a href=\"#\" onclick=\"" + getOnClick() + "\">");
    } else if (hasLink) {
      content.append("<a href=\"" + getLink() + "\">");
    }

    content.append("<span style='width:50px' class='text'>");
    content.append(MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), getLabel()));
    content.append("</span>");
    content.append("<div class='but_right_arrow'></div>");

    if (hasLink || hasOnClick) {
      content.append("</a>");
    }

    content.append("</span>");
    return content.toString();
  }

}
